//
//  DepositViewController.m
//  NiuBanJin
//
//  Created by zf on 15/10/17.
//  Copyright © 2015年 zzjr. All rights reserved.
//



#import "DepositViewController.h"
#import "DepositSuccessViewController.h"
#import "BCTextFieldForPlaceHolder.h"

@interface DepositViewController ()<UITextFieldDelegate,LLPaySdkDelegate>

@property (nonatomic, copy) NSString *str_amount ;// 当前余额
@property (nonatomic, copy) NSString *str_bankName;// 当前绑定的银行
@property (nonatomic, copy) NSString *str_cardNo; //当前绑定的card NO.
@property (nonatomic, copy) NSString *str_singleAmt; //当日的限额

@property (nonatomic, strong) LLPaySdk *sdk; //连连支付SDK
@property (nonatomic, copy) NSString *str_order_no; //得到的商务号

@property (nonatomic, assign) BOOL isDataGotten ;// 有没有得到数据

@end

@implementation DepositViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self pageSettingsAndSubviewsCreation];
}

- (void) viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self getDataFromServer];
    // 访问server得到最新的数据
}

#pragma mark - data preparation

- (void) getDataFromServer {
    
    //这接口得到用户绑定的银行卡
    NSDictionary *dic_params = @{@"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId)};
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrBankQueryByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            
            if ([dic_result[@"status"] integerValue] == 0) {
                
                self.str_cardNo = dic_result[@"result"][@"cardNo"];
                self.str_amount = dic_result[@"result"][@"amount"];
                self.str_bankName = dic_result[@"result"][@"bankName"];
                self.str_singleAmt = dic_result[@"result"][@"singleAmt"];
                
                if (![self.str_cardNo isEqualToString:@""]) {
                    
                    [self updateUI]; //更新UI
                }
                
            }else {
                
                [UsefulUtil showAlertView:dic_result[@"msg"]];
            }
      }else { //真正的网络错误
            
            [UsefulUtil showAlertView:error.description];
        }
    }];
}

- (void) updateUI { //查询 到了结果来更新UI
    
    //余额
    
    UILabel * label_balanceNumber = [self.view viewWithTag:65];
    label_balanceNumber.text  = [NSString stringWithFormat:@"%@",self.str_amount];
    
    //银行名字
    
    UILabel *label_bank = [self.view viewWithTag:66];
    NSString *str_cardNO_trail_4 = [[NSString stringWithFormat:@"%@",self.str_cardNo] substringWithRange:NSMakeRange(self.str_cardNo.length - 4, 4)];
    label_bank.text = [NSString stringWithFormat:@"    %@      尾号是%@              储蓄卡",self.str_bankName,str_cardNO_trail_4];
    
    //限额
    
    NSString *str_limit = [NSString stringWithFormat:@"*单笔限额%@元",self.str_singleAmt];
    UILabel * label_limit = [self.view viewWithTag:67];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:str_limit];
    
    [string addAttribute:NSForegroundColorAttributeName value:REDCOLOR range:NSMakeRange(0, 1)];
    [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, str_limit.length - 6)];
    
    label_limit.adjustsFontSizeToFitWidth = YES;
    label_limit.font = [UIFont systemFontOfSize:11.0];
    label_limit.attributedText = string;
}


#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {

    self.navigationItem.title = @"存入牛钱包";
    self.view.backgroundColor = BASECOLOR;
    UIView *view_white = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(100))];
    view_white.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_white];
    
    // 钱包余额显示
    
    UILabel *label_balance = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(131), MULTIPLYHEIGHT(21), MULTIPLYWIDTH(115), MULTIPLYHEIGHT(15))];
    label_balance.text = @"当前钱包余额(元)";
    label_balance.adjustsFontSizeToFitWidth = YES;
    label_balance.font = [UIFont systemFontOfSize:15.0];
    label_balance.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    [self.view addSubview:label_balance];
    
    
    UILabel *label_balanceNumber = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(label_balance.frame) + MULTIPLYHEIGHT(18), SCREEN_WIDTH, MULTIPLYHEIGHT(40.0))];
    label_balanceNumber.adjustsFontSizeToFitWidth = YES;
    label_balanceNumber.font = [UIFont systemFontOfSize:40];
    [label_balanceNumber setTextAlignment:NSTextAlignmentCenter];
    label_balanceNumber.textColor = [UsefulUtil colorWithHexString:@"#fb4747"];
    label_balanceNumber.tag = 65;

    label_balanceNumber.text  = [UserManager sharedUserManager].user.user_userAsset;
    
    [self.view addSubview:label_balanceNumber];
    
    // 存入金额
    
    UIView *view_white1 = [[UIView alloc]initWithFrame:CGRectMake(0 ,CGRectGetMaxY(view_white.frame) + MULTIPLYHEIGHT(20), SCREEN_WIDTH, MULTIPLYHEIGHT(50))];
    view_white1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_white1];
    UILabel *label_deposit = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(view_white.frame) + MULTIPLYHEIGHT(20), MULTIPLYWIDTH(90), MULTIPLYHEIGHT(50))];
    label_deposit.text = @"存入金额 (元)";
    label_deposit.font = [UIFont systemFontOfSize:15.0];
    label_deposit.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    label_deposit.adjustsFontSizeToFitWidth = YES;
    [self.view addSubview:label_deposit];
    
    BCTextField *field_deposit = [[BCTextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label_deposit.frame) + MULTIPLYWIDTH(22), CGRectGetMinY(label_deposit.frame) , MULTIPLYWIDTH(180), MULTIPLYHEIGHT(50))];

    [field_deposit setRegx:@"^[0-9]{0,6}+(\\.[0-9]{0,2})?$"];
    
    field_deposit.placeholder = @"请输入存入金额";
    [field_deposit setDelegate:self];
    field_deposit.adjustsFontSizeToFitWidth = YES;
    field_deposit.keyboardType = UIKeyboardTypeDecimalPad;
    field_deposit.delegate = self;
    [field_deposit addTarget:self action:@selector(profitCalculation:) forControlEvents:UIControlEventEditingChanged];
    [field_deposit setTag:22];
    
    [self.view addSubview:field_deposit];
    
    UILabel *label_exceptIncome = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(label_deposit.frame),SCREEN_WIDTH , MULTIPLYHEIGHT(32))];
    label_exceptIncome.tag = 300;

    [self.view addSubview:label_exceptIncome];
    
    UILabel *label_bank = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(label_exceptIncome.frame), SCREEN_WIDTH, MULTIPLYHEIGHT(60))];
    
    label_bank.backgroundColor = [UIColor whiteColor];
    label_bank.tag = 66;

    label_bank.text = @" "; //BUG 291,去掉默认值
    label_bank.font = [UIFont systemFontOfSize:15.0];
    label_bank.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    
    [self.view addSubview:label_bank];
    
    UILabel *label_limit = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(label_bank.frame) + MULTIPLYHEIGHT(12), SCREEN_WIDTH - MULTIPLYWIDTH(15), MULTIPLYHEIGHT(10))];

    label_limit.tag = 67;
    NSString *str_limit = @"*单笔限额50000元";
    
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:str_limit];
                                        
    [string addAttribute:NSForegroundColorAttributeName value:REDCOLOR range:NSMakeRange(0, 1)];
    [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, str_limit.length - 6)];

    
    label_limit.adjustsFontSizeToFitWidth = YES;

    label_limit.font = [UIFont systemFontOfSize:11.0];
    
    label_limit.attributedText = string;
    
    [self.view addSubview:label_limit];
    
    UIButton *button_next = [UIButton buttonWithType:UIButtonTypeSystem];
    button_next.frame = CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(label_limit.frame) + MULTIPLYHEIGHT(32),SCREEN_WIDTH - MULTIPLYWIDTH(15) * 2, MULTIPLYHEIGHT(45));
    [button_next setTitle:@"下一步" forState:UIControlStateNormal];
    button_next.backgroundColor = [UsefulUtil colorWithHexString:@"#fb4747"];
    button_next.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    button_next.tintColor = [UIColor whiteColor];
    [button_next addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_next];
    UIImageView *img_heart = [[UIImageView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(button_next.frame) + MULTIPLYHEIGHT(22),  MULTIPLYWIDTH(10), MULTIPLYHEIGHT(10))];
    img_heart.image = [UIImage imageNamed:@"heart.png"];
    
    [self.view addSubview:img_heart];
    UILabel *label_prompt = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(button_next.frame) + MULTIPLYHEIGHT(35), SCREEN_WIDTH - MULTIPLYWIDTH(30), MULTIPLYHEIGHT(40))];
    UILabel *label_prompt1 = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(28), CGRectGetMaxY(button_next.frame) + MULTIPLYHEIGHT(23), SCREEN_WIDTH - MULTIPLYWIDTH(10), MULTIPLYHEIGHT(8))];
    label_prompt1.text = @"温馨提示:";
    label_prompt1.font = [UIFont systemFontOfSize:12];
    [self.view addSubview:label_prompt1];
    label_prompt.text = @"移动端存入有限额,具体金额以银行金额为准.为了更多人享受牛钱包带来的便利,每人上限总额十万元。";
    label_prompt.numberOfLines = 2;
    label_prompt.font = [UIFont systemFontOfSize:12];
    label_prompt.adjustsFontSizeToFitWidth = YES;
    [self.view addSubview:label_prompt];
    
    UIImageView *img_safe = [[UIImageView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(105), SCREEN_HEIGHT - MULTIPLYHEIGHT(142), MULTIPLYWIDTH(10), MULTIPLYHEIGHT(12))];
    img_safe.image = [UIImage imageNamed:@"safe.png"];
    
    [self.view addSubview:img_safe];
    UILabel *label_safeText = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(img_safe.frame) + MULTIPLYWIDTH(3),CGRectGetMinY(img_safe.frame) - MULTIPLYHEIGHT(1) , MULTIPLYWIDTH(150), MULTIPLYHEIGHT(12))];
    label_safeText.text = @"牛钱包资金100%由银行监管";
    
    label_safeText.adjustsFontSizeToFitWidth = YES;
    
    [self.view addSubview:label_safeText];
}

#pragma mark - textfiled delegate

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    if (textField.tag == 22) { //金额框
        /**
         用户输入可能的情况是:
         009,
         09,
         09.
         09.9,
         09.99
         9.
         解决方案: 以. 为分隔
         */

        if ([textField.text componentsSeparatedByString:@"."].count == 1) { //处理009 ,09
            
            float value = textField.text.floatValue;
            textField.text = [NSString stringWithFormat:@"%.f",value];
  
        }else if ([textField.text componentsSeparatedByString:@"."].count == 2) { //处理09.，09.0，0.91
            
            if ([[[textField.text componentsSeparatedByString:@"."] lastObject] isEqualToString:@"0"]) {
                
                float value = textField.text.floatValue;
                textField.text = [NSString stringWithFormat:@"%.f",value];
            }else if([[textField.text  substringWithRange:NSMakeRange(textField.text.length -1 , 1)] isEqualToString:@"."]){
                
                float value = textField.text.floatValue;
                textField.text = [NSString stringWithFormat:@"%.f",value];
            }
        }
    }
}
-(void)profitCalculation:(BCTextField *) textFiled{

    CGFloat field = [textFiled.text floatValue];
    
    NSString *str_rate = [UserManager sharedUserManager].user.user_annualRate;
    NSString *str_rate_add = [UserManager sharedUserManager].user.user_ticketRate;
    
    // 计算是银行活期的多少倍
    CGFloat rate_total = [str_rate floatValue] + [str_rate_add floatValue];
    
    NSString *str_times = [NSString stringWithFormat:@"%.f",rate_total/0.25];
    
    CGFloat rate_real = (field + [self.str_amount floatValue])*rate_total/36500; //真实收益
    
    NSString *str_field = [NSString stringWithFormat:@"每日预期收益%.2f元,是银行活期的%@倍", rate_real, str_times];
    
    // 加红色字体
    NSMutableAttributedString *str_money = [[NSMutableAttributedString alloc]initWithString:str_field];

    [str_money addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6, [NSString stringWithFormat:@"%.2f",rate_real].length)];
    
    [str_money addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange((str_field.length - str_times.length -1), str_times.length)];
    
    // 显示值的label
    
    UILabel *label = [self.view viewWithTag:300];
    label.attributedText = str_money;
    label.font = [UIFont systemFontOfSize:11];
}



#pragma  mark -agetCode

-(void)agetCodeaAction:(UIButton *)sender{
    [UsefulUtil countDownMethodForButton:sender timeOutValue:10];
}

#pragma mark -nextAction

- (void)nextAction:(UIButton *)sender {

    BCTextField *textField = [self.view viewWithTag:22];
    
    if ([textField.text isEqualToString:@""] || (textField.text.floatValue < 0.001)) { //这儿记得改回100
        
        [UsefulUtil showAlertView:@"金额不能为空或小于100元!"];

        return;
    }else if(!self.str_cardNo){
        
        [UsefulUtil showAlertView:@"查询卡号为空!"];
        return;
    }else {
        
        //确认存入 ,这儿调用连连SDK
        
        NSDictionary *dic_params = @{@"userId":[UserManager sharedUserManager].user.user_userId,@"amountFee":textField.text,@"cardNo":self.str_cardNo,@"appRequest":@"2",@"payChannel":@"1",@"payPlatform":@"2"};
        
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        
        [[NetworkUtil sharedNetworkUtil] zzjrUserIDCardBindigByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            
            NSDictionary* dic_sign = parsedData ;
            
            if([dic_sign[@"status"] integerValue] == 0) {
                
                if ([dic_sign[@"result"] count] > 0 ) {
                    
                    NSLog(@"服务器返回的签名内容!:%@",dic_sign[@"result"]);
                    
                    self.str_order_no = dic_sign[@"result"][@"no_order"];
                    
                    [self.sdk presentVerifyPaySdkInViewController:self withTraderInfo:dic_sign[@"result"]];
                    
                }
                
            }else  {
                
                [UsefulUtil showAlertView:dic_sign[@"msg"]];
                
            }
        }];
    }
    
    
    // create one backgroundview
    
//    UIView *view_bg = [UsefulUtil viewCreationWithFrame:CURRENT_WINDOW.frame backgroundColor:[UIColor blackColor] backGroundImage:nil];
//    [view_bg setAlpha:0.5];
//    view_bg.tag = 203;
//    [CURRENT_WINDOW addSubview:view_bg];
//    
//    
//    UIView *view_next = [[UIView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(30.0),SCREEN_HEIGHT*1/4,  MULTIPLYWIDTH(632.0/2), MULTIPLYHEIGHT(489.0/2))];
//    view_next.backgroundColor = [UIColor whiteColor] ;
//    view_next.tag = 201;
//    [view_next.layer setCornerRadius:8.0];
//    
//    [CURRENT_WINDOW addSubview:view_next];
//    
//
//    UILabel *label_nextTiltle = [[UILabel alloc]initWithFrame:CGRectMake(0, MULTIPLYHEIGHT(50.0/2), view_next.bounds.size.width, MULTIPLYHEIGHT(40.0/2))];
//    label_nextTiltle.text = @"存入确认";
//    label_nextTiltle.adjustsFontSizeToFitWidth = YES;
//    [label_nextTiltle setTextAlignment:NSTextAlignmentCenter];
//    label_nextTiltle.font = [UIFont fontWithName:@"Helvetica-Bold" size:17 ];
//    [label_nextTiltle setTextColor:[UsefulUtil colorWithHexString:@"#434343"]];
//    [view_next addSubview:label_nextTiltle];
//    
//    // 消息发送提示
//    
//    NSString *stttr = @"13999999999";
//    NSString *str_msg = [NSString stringWithFormat:@"本次存入需要短信确认,验证码已经发送至您的手机%@",stttr];
//    UILabel *label_nextMessage = label_nextMessage = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(30.0/2), CGRectGetMaxY(label_nextTiltle.frame) + MULTIPLYHEIGHT(46.0/2), view_next.bounds.size.width - MULTIPLYWIDTH(60.0/2), MULTIPLYHEIGHT(80.0/2)) textColor:[UsefulUtil colorWithHexString:@"#434343"] fontName:[UIFont systemFontOfSize:17.0] text:str_msg];
//    label_nextMessage.numberOfLines = 0;
//    
//    [view_next addSubview:label_nextMessage];
//    
//    
//    UITextField *field_authenticationCode = [[UITextField alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(32.0 / 2), CGRectGetMaxY(label_nextMessage.frame) + MULTIPLYWIDTH(48.0 / 2), MULTIPLYWIDTH(190.0), MULTIPLYHEIGHT(50))];
//    [view_next addSubview:field_authenticationCode];
//    field_authenticationCode.placeholder = @"请输入6位验证码";
//    field_authenticationCode.font = [UIFont systemFontOfSize:15];
//    field_authenticationCode.backgroundColor = BASECOLOR;
//    
//    UIButton *button_agetCode = [UIButton buttonWithType:UIButtonTypeSystem];
//    
//    button_agetCode.frame = CGRectMake(CGRectGetMaxX(field_authenticationCode.frame) + MULTIPLYWIDTH(14.0), CGRectGetMinY(field_authenticationCode.frame), MULTIPLYWIDTH(80.0), MULTIPLYHEIGHT(50));
//    
//    [button_agetCode setTitle:@"获取" forState:UIControlStateNormal];
//    [button_agetCode addTarget:self action:@selector(agetCodeaAction:) forControlEvents:UIControlEventTouchUpInside];
//    button_agetCode.backgroundColor = BASECOLOR;
//    button_agetCode.titleLabel.font = [UIFont systemFontOfSize:15];
//    button_agetCode.tintColor = [UsefulUtil colorWithHexString:@"#434343"];
//    [view_next addSubview:button_agetCode];
//
//    
//    UIButton *button_cancel = [UIButton buttonWithType:UIButtonTypeSystem];
//    [button_cancel setTitle:@"取消" forState:UIControlStateNormal];
//    button_cancel.frame = CGRectMake(0, CGRectGetMaxY(field_authenticationCode.frame) + MULTIPLYHEIGHT(16), CGRectGetWidth(view_next.frame) / 2, MULTIPLYHEIGHT(60));
//    button_cancel.backgroundColor = [UIColor whiteColor];
//    [button_cancel setTitleColor:[UsefulUtil colorWithHexString:@"#434343"] forState:UIControlStateNormal];
//    button_cancel.layer.borderWidth = 1;
//    button_cancel.layer.borderColor = BASECOLOR.CGColor;
//    button_cancel.titleLabel.font = [UIFont systemFontOfSize:17];
//    [button_cancel addTarget:self action:@selector(canceAction:) forControlEvents:UIControlEventTouchUpInside];
//    [view_next addSubview:button_cancel];
//    
//    UIButton *button_sure = [UIButton buttonWithType:UIButtonTypeSystem];
//    [button_sure setTitle:@"确认" forState:UIControlStateNormal];
//    button_sure.frame = CGRectMake(CGRectGetWidth(view_next.frame) / 2, CGRectGetMaxY(field_authenticationCode.frame) + MULTIPLYHEIGHT(16), CGRectGetWidth(view_next.frame) / 2, MULTIPLYHEIGHT(60));
//    button_sure.backgroundColor = [UIColor whiteColor];
//    button_sure.layer.borderColor = BASECOLOR.CGColor;
//    button_sure.layer.borderWidth = 1;
//    [button_sure setTitleColor:[UsefulUtil colorWithHexString:@"#fb4747"] forState:UIControlStateNormal];
//    button_sure.titleLabel.font = [UIFont systemFontOfSize:17];
//    [button_sure addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
//    [view_next addSubview:button_sure];

}


// 连连支付SDK的回调
#pragma mark - lian lian sdk call back

- (void)paymentEnd:(LLPayResult)resultCode withResultDic:(NSDictionary*)dic {
    
    NSLog(@"连连支付SDK的回调:%@＝＝支付结果:%d",dic[@"ret_msg"],resultCode);
    
    // 如果支付成功，跳转到支付成功页面，看看支付成功，连连返回的数据决定
    
    if (resultCode == 0) {
        
        DepositSuccessViewController *successVC= [[DepositSuccessViewController alloc] init];
        BCTextField *textField = [self.view viewWithTag:22];
        [successVC setStr_amount:textField.text];
        
        [self.navigationController pushViewController:successVC animated:YES];
    }
}

#pragma mark -canceAction

- (void)canceAction:(UIButton *)sender {
   
    [sender.superview removeFromSuperview];
    UIView *view = (UIView *)[CURRENT_WINDOW viewWithTag:201];
    UIView *view_bg =(UIView *)[CURRENT_WINDOW viewWithTag:203];
    [view removeFromSuperview];
    [view_bg removeFromSuperview];
}

#pragma mark -sureAction 

- (void)sureAction:(UIButton *)sender {
    
    UIView *view = (UIView *)[CURRENT_WINDOW viewWithTag:201];
    UIView *view_bg =(UIView *)[CURRENT_WINDOW viewWithTag:203];
    [view removeFromSuperview];
    [view_bg removeFromSuperview];
    DepositSuccessViewController *succeddVC = [[DepositSuccessViewController alloc]init];
    [self.navigationController pushViewController:succeddVC animated:YES];
}

#pragma mark - setter methods

- (LLPaySdk *)sdk{
    
    if (!_sdk) {
        
        _sdk = [[LLPaySdk alloc] init];
        [_sdk setSdkDelegate:self];
    }
    
    return _sdk;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) backToPreviousPage {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
